package GUI.Gestion;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTable;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

public class Panel_empleado extends JPanel {
	private JTable tabla;
	private Panel_empleado yo = this;
	private JButton btnAadirEmpleado;
	private JButton btnBajaEmpleado;
	private JButton btnModificarEmpleado;
	private fachada_gestion fachada;
	private Connection con;

	/**
	 * Create the panel.
	 */
	public Panel_empleado(JTable table,fachada_gestion fachada,Connection c) {
		this.con=c;
		this.fachada = fachada;
		this.tabla = table;
		setLayout(new FormLayout(
				new ColumnSpec[] { ColumnSpec.decode("90dlu"), },
				new RowSpec[] { RowSpec.decode("31px"), RowSpec.decode("23px"),
						FormFactory.NARROW_LINE_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC, }));

		btnAadirEmpleado = new JButton("Add Empleado");
		btnAadirEmpleado.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				yo.fachada.DialogEmpl(yo, false,con);
			}
		});
		btnAadirEmpleado.setAlignmentX(Component.CENTER_ALIGNMENT);
		add(btnAadirEmpleado, "1, 1, fill, center");

		btnBajaEmpleado = new JButton("Baja Empleado");
		btnBajaEmpleado.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (yo.tabla.getSelectedRow() > 0) {
					Tabla modelo = (Tabla) yo.tabla.getModel();
					modelo.removeRow(yo.tabla.getSelectedRow());
					/////borrar empleado
					yo.tabla.setModel(modelo);
				}

			}
		});
		add(btnBajaEmpleado, "1, 2, fill, fill");

		btnModificarEmpleado = new JButton("Modificar Empleado");
		btnModificarEmpleado.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (yo.tabla.getSelectedRow() > 0) {
					yo.fachada.DialogEmpl(yo, true,con);
				}
			}
		});
		add(btnModificarEmpleado, "1, 4, fill, default");

	}

	public JTable getTabla() {
		return tabla;
	}

	public void setTabla(JTable tabla) {
		this.tabla = tabla;
	}

}
